#include <iostream>

using std::cout;
using std::endl;


class Base
{
public:
    Base()
    : _base(0)
    {   cout << "Base()" << endl;}

    Base(long base)
    : _base(base)
    {   
        cout << "Base(long)" << endl;
    }

    ~Base() {   cout << "~Base()" << endl;  }
    
    void print() const
    {   cout << "Base::_base:" << _base << endl;    }

    void print(int x) const 
    {   cout << "x:" << x << endl;}

private:
    long _base;
};

class Derived
: public Base
{
public:
    Derived(long base, long derived)
    : Base(base)
    , _derived(derived)
    {   cout << "Derived(long,long)" << endl;}

    ~Derived() {    cout << "~Derived()" << endl;}

    //在派生类中也定义了与基类同名的函数以后
    //发现通过派生类对象调用print函数时，只能调用到派生类的
    //调用不了基类的同名print函数, 这里发生了隐藏
    void print() const
    {   cout << "_derived:" << _derived << endl;    }


private:
    long _derived;
};

int main()
{
    Base base(11);
    base.print();//这里一定是调用基类的
    cout << endl;

    Derived d1(1, 2);
    d1.print();//发生隐藏
    //d1.print(10);//error,隐藏，看不到基类的带一个参数的print版本
    d1.Base::print();//如要调用基类的同名函数，必须要加上类名作用域限定符
    

    return 0;
}

